package com.yanqu.road.server.manger.union.listener;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.eUnionSyncType;
import com.yanqu.road.entity.rank.UnionRank;
import com.yanqu.road.entity.task.args.CommonActivityUnionRiseRankArgs;
import com.yanqu.road.entity.task.args.UnionRiseRankArgs;
import com.yanqu.road.entity.union.cross.CrossUnionInfo;
import com.yanqu.road.entity.union.cross.CrossUnionMember;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.ICrossUnionSyncListener;
import com.yanqu.road.server.manger.activity.CommonActivityMgr;
import com.yanqu.road.server.manger.cross.CrossDataMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.rank.RankMgr;
import com.yanqu.road.server.manger.union.CrossUnionMgr;

import java.math.BigInteger;
import java.util.List;

public class UnionDeleteListener implements ICrossUnionSyncListener {

    @Override
    public void notifySync(int syncType, long playerId, CrossUnionInfo unionInfo, List<CrossUnionMember> memberList) {

        if(syncType == eUnionSyncType.DeleteUnion.getValue()){

            //榜单移除
            RankMgr.removeUnionRank(unionInfo.getUnionUid());

            CrossUnionMember playerMember = null;
            for (CrossUnionMember member : memberList) {
                if(member.getUserId() == playerId){
                    playerMember = member;
                }
            }
            if(playerMember != null && playerMember.getServerId() == GameServer.getInstance().getServerId()){
                GamePlayer player = GamePlayerMgr.getOnlinePlayer(playerId);
                if(player != null){
                    notifyUnionActivityDeleteRank(player, unionInfo.getUnionUid());

                    //跨服分组榜单(掉榜)
                    UnionRank unionRank = new UnionRank();
                    unionRank.setUnionUid(unionInfo.getUnionUid());
                    unionRank.setUnionBaseInfo(CrossUnionMgr.parseUnionBaseInfo(unionInfo));
                    CrossDataMgr.groupUnionRankChange(unionRank);
                }
            }
        }

    }


    private static void notifyUnionActivityDeleteRank(GamePlayer player, String unionUid) {
        player.notifyListener(eGamePlayerEventType.UnionExpRiseRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_DELETE, BigInteger.ZERO, unionUid));
        player.notifyListener(eGamePlayerEventType.UnionIntimacyRiseRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_DELETE, BigInteger.ZERO, unionUid));
        player.notifyListener(eGamePlayerEventType.UnionTradeWarScoreRiseRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_DELETE, BigInteger.ZERO, unionUid));
        player.notifyListener(eGamePlayerEventType.UnionAbilityRiseRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_DELETE, BigInteger.ZERO, unionUid));
        player.notifyListener(eGamePlayerEventType.UnionEarnSpeedRiseRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_DELETE, BigInteger.ZERO, unionUid));
        player.notifyListener(eGamePlayerEventType.OreWarAcCoinOutPut.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_DELETE, BigInteger.ZERO, unionUid));
        player.notifyListener(eGamePlayerEventType.CrossOreWarAcCoinOutPut.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_DELETE, BigInteger.ZERO, unionUid));
        player.notifyListener(eGamePlayerEventType.DaFuWengUnionScoreRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_DELETE, BigInteger.ZERO, unionUid));
        player.notifyListener(eGamePlayerEventType.DaFuWengUnionDamageRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_DELETE, BigInteger.ZERO, unionUid));
        player.notifyListener(eGamePlayerEventType.BowArtActivityUnionScoreRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_DELETE, BigInteger.ZERO, unionUid));
        player.notifyListener(eGamePlayerEventType.BowArtActivityUnionScoreCrossRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_DELETE, BigInteger.ZERO, unionUid));
        player.notifyListener(eGamePlayerEventType.GhostUnionScoreRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_DELETE, BigInteger.ZERO, unionUid));
        player.notifyListener(eGamePlayerEventType.HangHaiUnionMoneyRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_DELETE, BigInteger.ZERO, unionUid));
        player.notifyListener(eGamePlayerEventType.DragonBoatRaceActivityUnionScoreRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_DELETE, BigInteger.ZERO, unionUid));
        player.notifyListener(eGamePlayerEventType.DragonBoatRaceActivityUnionScoreCrossRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_DELETE, BigInteger.ZERO, unionUid));
        player.notifyListener(eGamePlayerEventType.CookBoy1IntegralUserCrossRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_DELETE, BigInteger.ZERO, unionUid));
        player.notifyListener(eGamePlayerEventType.SeacraftPirateRiotUnionScoreRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_DELETE, BigInteger.ZERO, unionUid));
        player.notifyListener(eGamePlayerEventType.LangYaUnionScoreRank.getValue(), new UnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_DELETE, BigInteger.ZERO, unionUid));
        List<ActivityInfo> dataList = CommonActivityMgr.getInTimeCommonActivityInfoList(eActivityType.CommonActivity.getValue());
        for (ActivityInfo activityInfo : dataList) {
            player.notifyListener(eGamePlayerEventType.CommonActivityScoreRiseRank.getValue(), new CommonActivityUnionRiseRankArgs(UnionRiseRankArgs.NOTIFY_TYPE_DELETE, BigInteger.ZERO, unionUid, activityInfo.getChildType()));
        }
    }
}
